Ext.define('StaffServer.controller.RetireStaffHisController', {
	extend : 'Ext.app.Controller',

	models: ['RetireStaffModel','RetireStaffHisModel'],
	stores: ['RetireStaffStore','RetireStaffHisStore'],
	views:  ['retireStaffHis.RetireStaffHisGrid', 'retireStaffHis.RetireStaffHisMngr', 'retireStaffHis.RetireStaffHisSearchPanel', 'retireStaffHis.RetireStaffHisWindow', 'retireStaffHis.RetireStaffHisDetailGrid'],
	
	tabView: 'StaffServer.view.retireStaffHis.RetireStaffHisMngr',
	
	retireStaffHisWindow:null,
	
	refs : [ {
		ref : 'retireStaffHisSearchPanel',
		selector : 'retireStaffHisSearchPanel'
	}, {
		ref : 'retireStaffHisGrid',
		selector : 'retireStaffHisGrid'
	}, {
		ref : 'retireStaffHisDetailGrid',
		selector : 'retireStaffHisDetailGrid'
	}],

	// 初始化执行语句
	init : function() {
		retireStaffHisWindow = Ext.widget("retireStaffHisWindow");
		// 控制事件
		this.control({
			'retireStaffHisSearchPanel button[action=search]' : {
				click : this.search
			},
			'retireStaffHisSearchPanel button[action=reset]' : {
				click : this.reset
			},
			'retireStaffHisGrid button[action=staffHisInfo]' : {
				click : this.staffHisInfo
			},
			'retireStaffHisGrid button[action=exportExcel]' : {
				click : this.exportExcel
			},
			'retireStaffHisGrid': {
				itemdblclick: this.staffHisInfo
			},
			'retireStaffHisWindow button[action=close]' : {
				click : this.closeWindow
			}
		});
	},

	//searchPanel查询
	search : function() {
		var searchPanel = this.getRetireStaffHisSearchPanel();
		var grid = this.getRetireStaffHisGrid();
		grid.store.on('beforeload', function(store){
			var searchParams = searchPanel.getForm().getFieldValues();
			Ext.apply(store.proxy.extraParams, searchParams);
        });
		Ext.ComponentQuery.query('retireStaffHisGrid > pagingtoolbar')[0].moveFirst();
	},
	
	//searchPanel重置
	reset: function(){
		var searchPanel = this.getRetireStaffHisSearchPanel();
		searchPanel.getForm().reset();
	},
	
	
	staffHisInfo: function() {
		var record = this.getRetireStaffHisGrid().getSelectionModel().getLastSelected();
        if (Ext.isEmpty(record)) {
            Ext.Msg.alert('提示', '请先选择要操作的记录!');
            return;
        }
		var retireId = record.get("retireId");
		var retireStaffHisStore = this.getRetireStaffHisDetailGrid().getStore();
		retireStaffHisStore.on('beforeload', function(store){
            var sparams = {retireId: retireId};
        	Ext.apply(store.proxy.extraParams, sparams);
        });
		retireStaffHisStore.load();
		retireStaffHisWindow.setTitle("退休人员历史信息");
		retireStaffHisWindow.show();
	},
	
	
	exportExcel: function(){
		var searchPanel = this.getRetireStaffHisSearchPanel();
		var searchParams = searchPanel.getForm().getFieldValues();
		var jsonFilter = Ext.JSON.encode(searchParams);
		window.location.href = 'retireStaffHis/exportRetireStaffHisExcel?jsonFilter=' + jsonFilter;
	},
	
	closeWindow:function(){
		retireStaffHisWindow.hide();
	}
	
});